<?php

namespace App\Models\finance;

use App\Models\AdminModel;
use App\Models\CustomerModel;
use App\Models\TakeOrderModel;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model as BaseModel;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Illuminate\Database\Eloquent\SoftDeletes;

/**
 * @property int $id
 * @property string $airway_bill 运单号
 * @property int $customer_id 客户ID
 * @property string $flight_date 航班日期
 * @property string $flight_number 航班号
 * @property string $departure 始发地
 * @property string $destination 目的地
 * @property int $pieces 件数
 * @property float $gross_weight 毛重
 * @property float $volume_weight 体积重
 * @property float $chargeable_weight 计费重
 * @property float $pick_up_fee 提货费
 * @property float $handling_charge 操作费
 * @property float $customs_declaration_fee 报关费
 * @property float $mawb_documents_fee 主单文件费
 * @property float $total 总额
 * @property string $currency 币种
 * @property int $status 状态
 * @property int $take_order_id 关联主单ID
 * @property int $created_admin_id 创建人ID
 * @property string $created_at 创建时间
 * @property string $updated_at 更新时间
 * @property string $deleted_at 删除时间
 */
class ReceivableTemplate2Model extends BaseModel
{
    use HasFactory, SoftDeletes;

    protected $table = 't_receivable_template2';

    protected $primaryKey = 'id';

    public $timestamps = true;

    const CREATED_AT = 'created_at';
    
    const UPDATED_AT = 'updated_at';

    protected $guarded = [];

    protected $hidden = [
        'deleted_at',
    ];

    // 收款状态
    const STATUS_UNPAID = 1; // 未收款
    const STATUS_PARTIAL_PAID = 2; // 部分收款
    const STATUS_PAID = 3; // 已收款
    
    const STATUS_MAPS = [
        self::STATUS_UNPAID => '未收款',
        self::STATUS_PARTIAL_PAID => '部分收款',
        self::STATUS_PAID => '已收款',
    ];

    // 关联客户
    public function customer(): BelongsTo
    {
        return $this->belongsTo(CustomerModel::class, 'customer_id');
    }

    // 关联主单
    public function take_order(): BelongsTo
    {
        return $this->belongsTo(TakeOrderModel::class, 'take_order_id');
    }

    // 创建人
    public function create_admin(): BelongsTo
    {
        return $this->belongsTo(AdminModel::class, 'created_admin_id');
    }
} 